from typing import List, Tuple
from .db_context import DBConnection

async def insert_class_student(gid,stu_id):
    conn = DBConnection().connection
    cur = conn.cursor()
    cur.execute("INSERT INTO ClassStudent (gid, studentid) VALUES(?,?)",(gid,stu_id))
    cur.close()
    conn.commit()

async def get_class_student_list(gid):
    cur = DBConnection().connection.cursor()
    cur.execute('''
    SELECT studentid
    FROM ClassStudent
    WHERE gid=:gid
    ''', {"gid": gid})
    result = cur.fetchall()
    cur.close()
    return result

async def get_stu_class(studentid) -> List[Tuple]:
    cur = DBConnection().connection.cursor()
    cur.execute('''
    SELECT gid
    FROM ClassStudent
    WHERE studentid=:studentid
    ''', {"studentid": studentid})
    result = cur.fetchall()
    cur.close()
    return result